package com.weishi.tcp;

import com.weishi.common.utils.DateUtils;
import com.weishi.common.utils.GPSUtil;

import java.io.*;
import java.util.Date;

public class AnalysisResults {

    public static void main(String[] args) throws Exception {
        /*double mm = GPSUtil.GetDistance1(GPSUtil.changeDate(3150.0843),GPSUtil.changeDate(11708.6453),GPSUtil.changeDate(3150.0837),GPSUtil.changeDate(11708.6104));
        System.out.println(mm);*/

        readFileToResult();
    }

    private static void readFileToResult() throws Exception {
        File log = new File("D:\\temp\\sys-info.log");
//        File log1 = new File("D:\\temp\\sys-info1.log");
        File result = new File("D:\\temp\\result.csv");
        BufferedReader bReader = new BufferedReader(new FileReader(log));
        BufferedWriter bWriter = new BufferedWriter(new FileWriter(result));

        String strLine = null;
        Double lat1 = null;
        Double lng1 = null;
        Double time1 = null;
        Double latbe = null;
        Double lngbe = null;
        Double timebe = null;


        Double total = 0.0;



        //表头数据
        String tile = "时间,"+"维度,"+"精度,"+"与第一点距离,"+"与上一点距离,"+"与第一点时间,"+"与上一点时间,"+"速度,"+"总距离";
        bWriter.write(tile);
        bWriter.newLine();

        while ((strLine = bReader.readLine()) != null) {
            if (strLine.contains("P120010919")) {
              /*  bWriter.write(strLine);
                bWriter.newLine();*/
                String[] sss = strLine.split(",");
                //每秒取一个值
                /*if(!sss[3].contains(".00")){
                    continue;
                }*/
                String utc = sss[3]+"0";
                Date dateTime = DateUtils.dateTime("HHmmss.SSS",utc);
                double time = dateTime.getTime()/1000d;


                Double lat = GPSUtil.changeDate(Double.parseDouble(sss[4]));
                Double lng = GPSUtil.changeDate(Double.parseDouble(sss[6]));

                if (lat1 == null) {
                    lat1 = lat;
                    lng1 = lng;
                    latbe = lat;
                    lngbe = lng;
                    time1 = time;
                    timebe = time;
                    continue;
                }

                double mm1 = GPSUtil.GetDistance1(lat1, lng1, lat, lng);
                double mmbe = GPSUtil.GetDistance1(latbe, lngbe, lat, lng);
                if(time - timebe == 0){
                    continue;
                }
                double speed = (mmbe/(time - timebe));
                if(speed>10){
                    continue;
                }
                total += mmbe;

                bWriter.flush();
                bWriter.write(utc + "," + lat + "," + lng + "," + mm1 + "," + mmbe + "," + (time - time1) + "," + (time - timebe)+","+speed+","+total);
                // 记得换行
                bWriter.newLine();

                latbe = lat;
                lngbe = lng;
                timebe = time;

            }
        }

        bReader.close();
        bWriter.close();
    }

}
